************** this stata script replicates the results presented in tables S13,S15,S16 and S17 in supplementary materials *************


*structural diversity

clear all
import delimited "structural_diversity_data.txt" 

*only considering the number of active friends as endogenous variable
global dependent ego_distance_t
global engogenous_friends no_of_active_friends_t
global instruments_friends fr_rain_0_t
global engogenous_components no_of_active_friends_t
global instruments_components fr_rain_0_t
global engogenous_both no_of_active_friends_t no_of_components_who_run_t
global instruments_both fr_rain_3_t  fr_tmax_4_t 
global control_variables ego_distance_t_1 ego_tmax_t ego_prcp_t ego_connectivity_t av_fr_connectivity_t av_fr_age av_fr_age av_fr_weight portion_of_friends_that_male portion_of_friends_US portion_of_friends_UK portion_of_friends_JP portion_of_friends_CA portion_of_friends_wristdevice portion_of_friends_application1 portion_of_friends_application2

*only considering the number of active friends as endogenous variable
xi: ivreg2 $dependent  ($engogenous_friends  =   $instruments_friends) $control_variables i.ego_num i.day_num,  first small cluster(community_id)

*only considering the number of active cennected components as endogenous variable
xi: ivreg2 $dependent  ($engogenous_components  =   $instruments_components) $control_variables i.ego_num i.day_num,  first small cluster(community_id)

*by considering both the number of active friends and the number of active components
xi: ivreg2 $dependent  ($engogenous_both  =   $instruments_both) $control_variables i.ego_num i.day_num,  first small cluster(community_id)


*Embeddedness


clear all
import delimited "embedded_data.txt" 


global dependent ego_distance_t
global engogenous av_fr_distance_t
global instruments fr_rain_7_t   fr_tmax_2_t
global control_variables ego_distance_t_1 ego_tmax_t ego_prcp_t ego_connectivity_t av_fr_connectivity_t av_fr_age av_fr_age av_fr_weight portion_of_friends_that_male portion_of_friends_US portion_of_friends_UK portion_of_friends_JP portion_of_friends_CA portion_of_friends_wristdevice portion_of_friends_application1 portion_of_friends_application2

*embedded neighborhood
xi: ivreg2  $dependent  ( $engogenous =  $instruments )  $control_variables i.ego_num i.day_num if embedded==1,  first small cluster(community_id) 
*non-embedded neighborhood
xi: ivreg2  $dependent  ( $engogenous =  $instruments )  $control_variables i.ego_num i.day_num if embedded==0,  first small cluster(community_id)




